package client;

import javax.swing.table.AbstractTableModel;

public class MyTableModel extends AbstractTableModel
{
	public String[] columnNames = null;
    public Object[][] data = null;
    public String callFrom = null;
    
    public MyTableModel(Object[][] d, String[] columnN, String call)
    {
    	columnNames = columnN;
    	data = d;
    	callFrom = call;
    }
	  public int getColumnCount()
     {return columnNames.length;}

     public int getRowCount() 
     {return data.length;}

     public String getColumnName(int col) 
     {return columnNames[col];}

     public Object getValueAt(int row, int col) 
     {return data[row][col];}
     /**
      * JTable uses this method to determine the default renderer/
      * editor for each cell.  If we didn't implement this method,
      * then the last column would contain text ("true"/"false"),
      * rather than a check box.
      */
     public Class getColumnClass(int c)
     {return getValueAt(0, c).getClass();}

     /**
      * Don't need to implement this method unless your table's
      * editable.
      */
     public boolean isCellEditable(int row, int col) 
     {
    	 if(callFrom.equals("catalog"))
    	 {
	    	 if (col == 2 || col == 6 || col == 7) 
	         {return true;}
	         else {return false;}
    	 }
    	 else 
    		 if(callFrom.equals("cart"))
	    	 {
		    	 if (col == 5 || col == 7) 
		         {return true;}
		         else {return false;}
	    	 }
    	 else 
    		 if(callFrom.equals("customCart"))
	    	 {
		    	 if (col == 4 || col == 5 || col == 6) 
		         {return true;}
		         else{return false;}
	    	 }
    	 else 
        	 if(callFrom.equals("order"))
    	     {
    		     if (col == 4 || col == 5) 
    		     {return true;}
    		     else{return false;}
    	     }
         else 
             if(callFrom.equals("catalogManaging"))
        	 {
             	 if (col == 7) 
             	 {return true;}
            	 else{return false;}
        	 }
    	 else //if(callFrom.equals("ItemsInCustomItem"))
    	 {
	    	 if (col == 6) 
	         {return true;}
	         else{return false;}
    	 }
     }
     /**
      * Don't need to implement this method unless your table's
      * data can change.
      */
     public void setValueAt(Object value, int row, int col) {
         data[row][col] = value;
         fireTableCellUpdated(row, col);
     }
}
